package com.qsl.ssyx.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.product.Category;
import com.qsl.ssyx.product.service.AttrGroupService;
import com.qsl.ssyx.product.service.CategoryService;
import com.qsl.ssyx.vo.product.AttrGroupQueryVo;
import com.qsl.ssyx.vo.product.CategoryQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-11
 */
@Api(tags = "商品分类接口")
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("查詢所有商品")
    @GetMapping("findAllList")
    public Result findAllList() {
        List<Category> categoryList = categoryService.list();
        return Result.ok(categoryList);
    }


    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result selectPage(@ApiParam(value = "当前页") @PathVariable Integer page
            , @ApiParam(value = "每页记录数") @PathVariable Integer limit
            , CategoryQueryVo categoryQueryVo) {
        Page<Category> pageParam = new Page<>(page, limit);
        IPage<Category> model = categoryService.selectPage(pageParam, categoryQueryVo);
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody Category category) {
        boolean flag = categoryService.save(category);

        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @GetMapping("getById/{id}")
    public Result save(@ApiParam(value = "id") @PathVariable("id") Integer Id) {
        Category category = categoryService.getById(Id);
        return Result.ok(category);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody Category category) {
        boolean flag = categoryService.updateById(category);
        return Result.ok(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = categoryService.removeById(Id);
        return Result.ok(flag);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Integer> idList) {
        boolean flag = categoryService.removeByIds(idList);
        return Result.ok(idList);
    }


}

